package com.gelsanalyzer.business;

import java.util.*;

public class GoalOptimizer {    
//TODO code this to optimize a CourseEntryList
    
private CourseEntryList cel;
private List<CourseEntryItem> CEIList;
private short[] goalArray;
private final static  int NUM_GOALS=12;

public GoalOptimizer(CourseEntryList cel) {    
    this.cel = cel;
    goalArray = new short [NUM_GOALS];
    for(int i=0; i<NUM_GOALS; i++) 
        goalArray[i] = 0;
    CEIList = cel.getCourseList();
        
    
    Runnable r = new Runnable() {
        public void run()  {
            runWork();
        }
    };
    
    Thread t = new Thread(r);
    t.start();
}

private void print() {
    for(int i=0; i<NUM_GOALS; i++) {   
        System.out.print("Goal area " + i + ": ");
        System.out.println(goalArray[i]);
    }
}

private void runWork() {
    List<Goalarea> list = new ArrayList<Goalarea>();
    for(int i=0; i<cel.getCount(); i++) { //iterate through the entire list of courses
        list = cel.getCourseList().get(i).getGoalarea();
        for(int c=0; c<list.size(); c++)         
            for(int x=0; x<list.get(c).getGoalAsNum().size(); x++)
                goalArray[list.get(c).getGoalAsNum().get(x)] +=
                    cel.getCourseList().get(i).getCourse().getCourseCredits();   
        //goalArray is now filled with the number of credits the student has applied to each goal
        //can verify by running com.gelanalyzer.OptimizerTest.java       
        
    }
    print();
}


}
